#! /usr/bin/perl -w
##########################################################################
#
# FILE  makesinus.pl
# Copyright (c) 2003 Daniel Kahlin <daniel@kahlin.net>
# Written by Daniel Kahlin <daniel@kahlin.net>
# $Id: makesinus.pl,v 1.1 2006-07-24 17:37:21 tlr Exp $
#
# DESCRIPTION
#   Generate sinus-tables as source code.
#
#
######
use strict;
use Getopt::Std;

my $PROGRAM="makesinus.pl";
my $PROGRAM_VERSION="0.0.2";

# globals
my $debug_g;
my $verbose_g;

##########################################################################
#
# the MAIN code
#
# checks command line arguments
# prints help if appropriate, calls process_file() for
# all specified files.
#
######
my %opts;

# defaults
my $len=128;
my $size=64;
my $name="sin1";

getopts ('s:l:n:vdVh',\%opts);

$verbose_g=$opts{v};
$debug_g=$opts{d};

# print version and exit if -V
if ($opts{V}) {
    print $PROGRAM," ",$PROGRAM_VERSION,"\n";
    exit 0;
}

# print help and exit if -h
if ($opts{h}) {
    print <<EOF;
$PROGRAM $PROGRAM_VERSION - make sinus tables.
Copyright (c) 2003 Daniel Kahlin <daniel\@kahlin.net>

USAGE: $PROGRAM [-h][-V][-v][-d][-l<len>][-s<size>][-n<name>]
  -l <len> length of table to generate.
  -s <size> peak to peak size.
  -n <name> name of label.
  -h display this help text
  -V display version
  -v be verbose
  -d dump lots of (weird) debugging info
EOF
    exit 0;
}

if ($opts{s}) {
    $size=$opts{s};
}
if ($opts{l}) {
    $len=$opts{l};
}
if ($opts{n}) {
    $name=$opts{n};
}

#
# Information gathered, act on it!
#
my $i;

my $linelen=12;
printf "; generated by $PROGRAM $PROGRAM_VERSION\n";
printf "; len=$len, size=$size\n";
printf "%s:\n",$name;
for ($i=0; $i<$len; $i++) {
    if ($i%$linelen==0) {
	printf "\tdc.b\t";
    }
    my $arg=($i/$len)*2*3.1415;
    my $pt=(($size/2)+sin($arg)*($size/2))+0.5;
    printf "\$%02x",$pt;
    if ($i%$linelen==$linelen-1 || $i==$len-1) {
	printf "\n";
    } else {
	printf ",";
    }
}
printf "%send:\n",$name;



# eof
